/**
 * Created by Fly on 2016/9/22.
 */
$(function () {
    $('#pet_varietie').each(function () {
        var url="/javascripts/varietie.json";
        var varietieJson;
        var temp;
        var family=$(this).find('#mySelect0');
        var varietie=$(this).find('#mySelect1');
        //var odistrict=$(this).find('.sel_street');
        //获取json数组
        $.getJSON(url,function (data) {
            varietieJson=data;
            fun_family();
        })
        //赋值省

        var  fun_family=function () {

            $.each(varietieJson,function(i,sel_family){
                temp+="<option value='"+sel_family.family+"'>"+sel_family.family+"</option>";
            });
            // family.html("请选择宠物分类");

            family.html(temp);
            fun_varietie();
        }
        //赋值市

        var fun_varietie = function(){
            temp = "";
            var n = family.get(0).selectedIndex;

            $.each(varietieJson[n].varietie,function(i,sel_varietie){
                temp+="<option value='"+sel_varietie+"'>"+sel_varietie+"</option>";
            });
            // varietie.html("请选择宠物品种");
            varietie.html(temp);
        };
        //选择一级改变二级
        family.change(function(){
            fun_varietie();
        });
    })

})